# Maintainer: Alexander F. Rødseth <xyproto@archlinux.org>
# Maintainer: kpcyrd <kpcyrd@archlinux.org>
# Maintainer: Caleb Maclennan <caleb@alerque.com>
# Contributor: Lucas Raab <tuftedocelot@fastmail.fm>

pkgname=exa
pkgver=0.10.1
pkgrel=7
pkgdesc='ls replacement'
arch=(loong64 x86_64)
url='https://the.exa.website/'
license=(MIT)
depends=(libgit2.so)
makedepends=(cargo git pandoc)
source=("$pkgname-$pkgver.tar.gz::https://github.com/ogham/exa/archive/v$pkgver.tar.gz")
b2sums=('07f489fc0f3a755ea4ac6374e6ebd7b17d8d4fc6de92e695ea9b2868bcbca9c6f2788ec11329d0051abc2ffb8d1746898bdcef8a1d18ba9d67c94a627d30b6e2')

prepare() {
  cd $pkgname-$pkgver
  # Fix outdated Cargo.lock
  sed -i 's/version = "0.11.0-pre"/version = "0.10.1"/' Cargo.lock
  cargo fetch --locked --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd $pkgname-$pkgver
  cargo build --frozen --release
  for manpage in exa.1 exa_colors.5; do
    pandoc --standalone -f markdown -t man man/$manpage.md > $manpage
  done
}

package() {
  cd $pkgname-$pkgver
  install -Dm755 target/release/exa -t "$pkgdir/usr/bin"
  install -Dm644 completions/completions.bash \
    "$pkgdir/usr/share/bash-completion/completions/$pkgname"
  install -Dm644 completions/completions.zsh \
    "$pkgdir/usr/share/zsh/site-functions/_$pkgname"
  install -Dm644 completions/completions.fish \
    "$pkgdir/usr/share/fish/vendor_completions.d/$pkgname.fish"
  install -Dm644 LICEN?E \
    "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
  install -Dm644 exa.1 "$pkgdir/usr/share/man/man1/exa.1"
  install -Dm644 exa_colors.5 "$pkgdir/usr/share/man/man5/exa_colors.5"
}
